home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) Silicon Graphics, Inc. 1996 */
-
- /* abgr.c
- * Demonstrates the GL_EXT_abgr extension. This program creates
- * an image which consists of 4 stripes, each with only one
- * component set to 0xff, and the rest set to 0. This image is
- * then used as a texture which is applied first using RGBA format,
- * and then again with ABGR_EXT format.
- *
- * Escape key - exit program
- */
- #include <GL/glut.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid drawScene( GLvoid );
- GLvoid reshape( GLsizei, GLsizei );
- GLvoid keyboard( GLubyte, GLint, GLint );
-
- GLvoid printHelp( char * );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- /* Global Variables */
- GLubyte ubImage[65536];
- GLubyte *image;
-
- GLvoid
- main ( int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- width = glutGet(GLUT_SCREEN_WIDTH);
- height = glutGet(GLUT_SCREEN_HEIGHT);
- glutInitWindowPosition( width/8, height/8);
- glutInitWindowSize( 400, 400 );
- glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutReshapeFunc( reshape );
- glutDisplayFunc( drawScene );
-
- printHelp( argv[0] );
-
- glutMainLoop();
- }
-
- GLvoid
- printHelp( char *progname )
- {
- fprintf(stdout, "\n%s - demonstrates GL_EXT_abgr extension\n"
- "Escape key - exit the program\n\n",
- progname);
- }
-
- GLvoid
- initgfx( GLvoid )
- {
- int j;
- glClearColor( 0.5, 0.5, 0.5, 1.0 );
-
- if ( !glutExtensionSupported( "GL_EXT_abgr" ) ) {
- fprintf(stderr,
- "EXT_abgr not supported in this implementation\n");
- }
-
-
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
-
- /* Create image */
- image = ubImage;
- for (j = 0; j < 32 * 128; j++) {
- *image++ = 0xff;
- *image++ = 0x00;
- *image++ = 0x00;
- *image++ = 0x00;
- }
- for (j = 0; j < 32 * 128; j++) {
- *image++ = 0x00;
- *image++ = 0xff;
- *image++ = 0x00;
- *image++ = 0x00;
- }
- for (j = 0; j < 32 * 128; j++) {
- *image++ = 0x00;
- *image++ = 0x00;
- *image++ = 0xff;
- *image++ = 0x00;
- }
- for (j = 0; j < 32 * 128; j++) {
- *image++ = 0x00;
- *image++ = 0x00;
- *image++ = 0x00;
- *image++ = 0xff;
- }
- image = ubImage;
-
- }
-
- GLvoid
- reshape( GLsizei width, GLsizei height )
- {
- GLdouble aspect;
-
- glViewport( 0, 0, width, height);
-
- aspect = (GLdouble) width / (GLdouble) height;
-
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- gluPerspective(60.0, aspect, 0.1, 1000.0);
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case KEY_ESC: /* Exit whenever the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- glClear( GL_COLOR_BUFFER_BIT );
-
- glRasterPos3f(0.2, -0.8, -1.5);
- glDrawPixels(128, 128, GL_RGBA, GL_UNSIGNED_BYTE, image);
- #ifdef GL_EXT_abgr
- glRasterPos3f(-0.8, -0.8, -1.5);
- glDrawPixels(128, 128, GL_ABGR_EXT, GL_UNSIGNED_BYTE, image);
- #endif
-
- glEnable(GL_TEXTURE_2D);
- glTexImage2D(GL_TEXTURE_2D, 0, 3, 128, 128, 0, GL_RGBA,
- GL_UNSIGNED_BYTE, image);
- glBegin(GL_POLYGON);
- glTexCoord2f(1.0, 1.0); glVertex3f(-0.2, 0.8, -100.0);
- glTexCoord2f(0.0, 1.0); glVertex3f(-0.8, 0.8, -2.0);
- glTexCoord2f(0.0, 0.0); glVertex3f(-0.8, 0.2, -2.0);
- glTexCoord2f(1.0, 0.0); glVertex3f(-0.2, 0.2, -100.0);
- glEnd();
- #ifdef GL_EXT_abgr
- glTexImage2D(GL_TEXTURE_2D, 0, 3, 128, 128, 0, GL_ABGR_EXT,
- GL_UNSIGNED_BYTE, image);
- #endif
- glBegin(GL_POLYGON);
- glTexCoord2f(1.0, 1.0); glVertex3f(0.8, 0.8, -2.0);
- glTexCoord2f(0.0, 1.0); glVertex3f(0.2, 0.8, -100.0);
- glTexCoord2f(0.0, 0.0); glVertex3f(0.2, 0.2, -100.0);
- glTexCoord2f(1.0, 0.0); glVertex3f(0.8, 0.2, -2.0);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- glutSwapBuffers();
- }
-